<?php
declare (strict_types=1);

namespace app\admin\controller;


use addons\Builder\facade\Builder;
use think\App;

class SummaryDate extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\SummaryDate';


    public function index(): string
    {
        $table = Builder::Table()
            ->addColumn(['field' => 'create_date', 'fixed' => 'left', 'title' => '日期', 'width' => 120, 'totalRowText' => '合计']);
        foreach (getBonusTitle(2) as $k => $v) {
            $table->addColumn(['field' => $k, 'templet' => '<span>{{d.' . $k . '}}</span>', 'title' => $v, 'totalRow' => true]);
        }
        $table->addColumn(['field' => 'update_time', 'title' => '更新时间']);
        $table->addColumn(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 200]);

        return $table->addSearch([
            ['create_date', '日期筛选', 'date']
        ], false)
            ->addTopButtons(['export'])
            ->addRightButtons([
                'summary_info' => [
                    'title' => '查看明细',
                    'type'  => 'summary_info',
                    'url'   => url('summary_info')->build(),
                    'event' => '_openNewPage',
                    'size'  => '90%',
                    'site'  => 'r'
                ]
            ])
            ->setTotalRaw('true')
            ->addJsUrl(['summary'])
            ->fetch();
    }

    public function summary_info($id)
    {
        $info = $this->model::find($id);
        $s = $info->create_date . ' - ' . date("Y-m-d", strtotime("+1 day", strtotime($info->create_date)));
        $url = url('account/bonus') . '?times=' . $s . '&summary=1';
        return redirect($url);

    }

}
